package com.ybjzo2o.customer.utils;

import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.json.JSONUtil;
import java.nio.charset.StandardCharsets;

public class RsaUtils {
    public RsaUtils() {
    }

    public static <T> String encrypt(T data, RSA rsa) {
        byte[] encrypt = rsa.encrypt(JSONUtil.toJsonStr(data).getBytes(StandardCharsets.UTF_8), KeyType.PrivateKey);
        return Base64Utils.encodeToString(encrypt);
    }

    public static <T> String encrypt(T data, String privateKey) {
        return encrypt(data, new RSA(privateKey, (String)null));
    }
}